import { _decorator, Component, Node, UITransform } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Bg')
export class Bg extends Component {

    private active: boolean = false

    // @property({type: Node})
    private bg_1: Node | null = null;
    // @property({type: Node})
    private bg_2: Node | null = null;

    start() {
        // this.bg_2.setPosition(0,1200);
    }

     //背景滚动
    runBg(){
        // const tsf1 = this.bg_1.getComponent(UITransform);
        // const tsf2 = this.bg_2.getComponent(UITransform);
        // this.downToUp(tsf1, tsf2);
    }

    // 上下滚动
    topToDown( tsf1:UITransform, tsf2:UITransform){
        this.bg_1.setPosition(this.bg_1.position.x, this.bg_1.position.y - 2);
        this.bg_2.setPosition(this.bg_2.position.x, this.bg_2.position.y - 2);
        if(this.bg_1.position.y <= -tsf1.height){
            this.bg_1.setPosition(this.bg_1.position.x, this.bg_2.position.y + tsf1.height);
        }
        if(this.bg_2.position.y <= -tsf2.height){
            this.bg_2.setPosition(this.bg_2.position.x, this.bg_1.position.y + tsf2.height);
        }
    }

    // 下上滚动
    downToUp( tsf1:UITransform, tsf2:UITransform){
        // this.bg_1.setPosition(this.bg_1.position.x, this.bg_1.position.y + 2);
        // this.bg_2.setPosition(this.bg_2.position.x, this.bg_2.position.y + 2);
        if(this.bg_1.position.y >= tsf1.height){
            this.bg_1.setPosition(this.bg_1.position.x, this.bg_2.position.y - tsf1.height);
        }
        if(this.bg_2.position.y >= tsf1.height){
            this.bg_2.setPosition(this.bg_2.position.x, this.bg_1.position.y - tsf2.height);
        }
    }


    update(deltaTime: number) {
        
    }
}

